<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            var currentPage = 1;//默认第一页
            var pages; //总页数
            var travelArr = [];//用户存储游记文章的容器
            var loading = false;//标记是否查询中

            function query() {//分页查询
                if(loading){//代表正在查询,就直接结束方法
                    return;
                }
                loading = true;//标记正在查询中;
                $.get(baseUrl +"/travels", {currentPage: currentPage}, function (data) {
                    $.merge(travelArr,data.list );//合并数据,把第二个参数的数据合并到第一个参数的容器中
                    var json = {list:travelArr};//用于render-loop="list"
                    $("#allTravels").renderValues(json,{
                        getHref:getHref
                    });//使用合并后的容器来进行渲染,但是必须要有list的属性名称
                    currentPage++;//当前页数+1
                    pages = data.pages;//设置总页数
                    loading = false;//标记查询结束
                })
            }

            query();//默认查询第一页

            //监听窗口的滚动事件
            $(window).scroll(function () {
                console.log("窗口滚动中...")
                if($(document).scrollTop()+$(window).height()>=$(document).height()){//滚动到底部
                    //如果已经查询到最后一页,就不再查
                    if(currentPage<=pages) {
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            content: '<span class="info-text">已经到底了!</span>',
                            autoClose: 1500
                        });
                    }
                }

            })

            //给查询按钮绑定事件
            $("#searchBtn").click(function () {
                var keyword = $("#search").val();
                if(keyword!=null&keyword!=""){
                    window.location.href="/searchPage.html?keyword="+keyword+"&type=2";
                }else{
                    $(document).dialog({
                        titleText: '温馨提示',
                        content: '搜索内容不能为空!',
                    });
                }
            });




        })
    </script>
</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-1">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-9">
            <div class="input-group-sm search">
                <input id="search" class="form-control" placeholder="搜游记">
            </div>
        </div>
        <div class="col-1">
            <i class="fa fa-search" id="searchBtn"
               style="color:white;font-size:25px;position: absolute;top: 23%;left: 0%">
            </i>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div ><div class="carousel-item active">
                <div class="border commend">
                    <a href="travelContent.html">
                        <img src="/upload/acd22908-8780-4e81-8468-8dac6724b8d1.jpeg" width="100%" height="200px">
                        <h1 > 骨灰级成都吃货地图</h1>
                        <small >成都成都</small>
                    </a>
                </div>
            </div></div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels" >
      <div render-loop="list">
        <div class="row detail">
            <div class="col">
                <a render-key="list.id" render-fun="getHref" data-url="/travelContent.html?id=">
                    <h4 render-html="list.title"> </h4>
                </a>
                <p>
                    <a render-key="list.author.id" render-fun="getHref" data-url="/userProfiles.html?id=" >
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName"></span> </a> 在
                    <span class="addr" render-html="list.place.name">成都</span>

                </p>
                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span>0</span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span>0</span>
                </p>
            </div>
            <div class="col bigimg">
                <a render-key="list.id" render-fun="getHref" data-url="/travelContent.html?id=" >
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
      </div>
    </div>
</div>



</body>

</html>